package com.Akronmcp.hopMessage;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/**网络线程类,用于读取网络信息*/
public class HmWeb extends Thread{


	public HmWeb(String url)
	{
		this.url = url;
	}
	
	String url;
	
	String result = "undefined";
	
	public void run()
	{
		
		   BufferedReader reader = null;
	       StringBuffer sbf = new StringBuffer();
	       
		
		try 
		{//读取
			
			URL url = new URL(this.url);
	
			HttpURLConnection connection = (HttpURLConnection) url
					.openConnection();
			connection.setRequestMethod("GET");
			InputStream is = connection.getInputStream();
			InputStreamReader isr = new InputStreamReader(is, "UTF-8");
			reader = new BufferedReader(isr);
			String strRead = null;
			while ((strRead = reader.readLine()) != null) {
				sbf.append(strRead);
				sbf.append("\r\n");
			}
			
			reader.close();
			isr.close();
			is.close();
		
			connection.disconnect();
			result = sbf.toString();
			//获得返回数据
			
			
		} catch (Exception e) 
		{
			e.printStackTrace();
			System.out.println("网络开小差了? ");
		}
		
	}
	
	
	public String getResult()
	{
		return result;
	}
	
}
